package com.chris.serve;

import com.chris.entity.menu;
import com.chris.impl.menuImpl;
import com.chris.utils.JsonProcess;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.List;

@WebServlet("/journalTop10")
public class journalTop10 extends HttpServlet {
    private menuImpl dao = new menuImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        PrintWriter writer = resp.getWriter();
        try {
            List<menu> dao10 = dao.get10();
            writer.print(JsonProcess.respSuccess("成功",dao10));
        } catch (SQLException throwables) {
            writer.print(JsonProcess.respError("参数错误"));
            throwables.printStackTrace();
        }
    }
    public void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.addHeader("Access-Control-Allow-Headers", "*");
    }
}
